package com.wj.infrastructure.mapper;

import com.wj.domain.vo.BookShelfVO;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * @description: 
 * @author: wj
 * @create: 2021/11/30 14:35
 */
@Mapper
public interface BookShelfMapper {

    @Results(value = {
            @Result(property = "id", column = "id"),
            @Result(property = "bookId", column = "bookId"),
            @Result(property = "bookName", column = "book_name"),
            @Result(property = "bookUrl", column = "book_url"),
            @Result(property = "author", column = "author"),
            @Result(property = "type", column = "type"),
            @Result(property = "newest", column = "newest"),
            @Result(property = "state", column = "state"),
            @Result(property = "number", column = "number"),
            @Result(property = "bookDesc", column = "book_desc"),
            @Result(property = "imgUrl", column = "img_url"),
            @Result(property = "views", column = "views"),
            @Result(property = "updateTime", column = "update_time"),
            @Result(property = "sort", column = "sort"),
    })
    @Select(" select s.id, a.id as bookId,a.book_name,a.book_url,a.author,a.type," +
            " a.newest,a.state,a.number,a.book_desc,a.img_url,a.views, a.update_time,s.sort " +
            " from book_shelf s " +
            " join book a on s.book_id=a.id" +
            " where s.user_id = #{userId}")
    List<BookShelfVO> queryListByUserId(@Param("userId") Long userId);

    @Select(" select c.id,s.book_id as bookId, s.sort, c.content_id as content_id, " +
            " c.chapter_title as chapterTitle,c.create_time as updateTime " +
            " from book_shelf s " +
            " join chapter c on c.sort=s.sort and c.book_id=s.book_id  " +
            " where user_id = #{userId} and s.book_id= #{bookId}")
    BookShelfVO getMyShelfChapterInfo(@Param("userId") Long userId, @Param("bookId") Long bookId);
}
